class MapApiService {
  static getCategories() {
    return fetch('/tencent-map/api/shop-categories/')
      .then(response => response.json())
      .catch(error => {
        console.error('获取分类失败:', error);
        return [];
      });
  }

  static searchShops(lat, lng, radius = 1000, keyword = '店铺', category = '') {
    const params = new URLSearchParams({
      latitude: lat,
      longitude: lng,
      radius: radius,
      keyword: keyword,
      category: category
    });

    return fetch(`/tencent-map/api/nearby-shops/?${params}`)
      .then(response => response.json())
      .then(data => {
        if (data.success) {
          return data.data;
        } else {
          throw new Error(data.message);
        }
      })
      .catch(error => {
        console.error('搜索店铺失败:', error);
        return [];
      });
  }

  static getShopDetails(shopId) {
    return fetch(`/tencent-map/api/shop-details/${shopId}/`)
      .then(response => response.json())
      .then(data => {
        if (data.success) {
          return data.data;
        } else {
          throw new Error(data.message);
        }
      })
      .catch(error => {
        console.error('获取店铺详情失败:', error);
        return null;
      });
  }
}